package ${package.Controller?replace(".controller","")}.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import ${package.Entity}.SysUser;
import ${package.Controller?replace(".controller","")}.sys.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import ${package.Entity}.SysUser;
import ${package.Controller?replace(".controller","")}.sys.dao.SysUserDao;
import ${package.Controller?replace(".controller","")}.sys.service.LoginService;
import ${package.Controller?replace(".controller","")}.util.Md5HashUtil;
import ${package.Controller?replace(".controller","")}.util.RandomUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author yiming
* @title: LoginServiceImpl
* @projectName property
* @description: TODO
* @date 2019/6/1220:33
*/
@Service
public class LoginServiceImpl implements LoginService {
@Autowired
private SysUserDao dao;

@Override
public SysUser getByUsername(String username) {
return  dao.getByUsername(username);
}

@Override
public int create(SysUser model) {
String salt= RandomUtil.generateString(8);
model.setSalt(salt);
model.setPassword(Md5HashUtil.getMd5(model.getPassword(),salt));
return dao.insert(model);
}
@Override
public int update(SysUser model){
if(!StringUtils.isEmpty(model.getPassword())){
String salt= RandomUtil.generateString(8);
model.setSalt(salt);
model.setPassword(Md5HashUtil.getMd5(model.getPassword(),salt));
}
QueryWrapper<SysUser> queryWrapper=new QueryWrapper();
    queryWrapper.eq("username",model.getUsername());
    return dao.update(model,queryWrapper);
    }
    }